﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Liang.Util
{
    /// <summary>
    /// 字符串处理类
    /// </summary>
    public static class FormatString
    {
        /// <summary>
        /// 按指定间隔插入字符串
        /// </summary>
        /// <param name="srcStr"></param>
        /// <param name="flag"></param>
        /// <param name="step"></param>
        /// <returns></returns>
        public static string InsertFlag(string srcStr, string flag, int step)
        {
            if (0 >= step || srcStr.Length < step)
            {
                return srcStr;
            }

            string ret = "";

            for (int i = 0; i < srcStr.Length; i += step)
            {
                if (i + step < srcStr.Length)
                    ret += srcStr.Substring(i, step) + flag;
                else
                    ret += srcStr.Substring(i);
            }

            return ret;
        }
    }
}
